package nuovoLogin;

import java.awt.Dimension;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPasswordField;
import javax.swing.JTextField;
import javax.swing.SwingUtilities;

import login.Errore;
import login.ImagePanell;
import login.PagPers;

public class AccessoStudente extends JFrame implements ActionListener{
	private JDialog frame;
	 private static JButton Entra=new JButton("Entra");
	    final JTextField user_tf = new JTextField();
	    final JPasswordField pass_tf = new JPasswordField();
	   private static String usr = "user";
	    private static String psw = "password";
	public AccessoStudente(){
		frame=new JDialog();
		        frame.setTitle("STUDENTE");
		        frame = new JDialog();
		        frame.setModal(true);
		        frame.setLocation(350, 150);
		       
				 frame.setSize(700,400);
				 frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
				 ImagePanell panel= new ImagePanell   (new ImageIcon("C:\\Users\\acer\\workspace1\\LaboratorioDiAlgoritmi\\src\\Image\\images-3.jpg").getImage());
			   	 frame.getRootPane().add(panel);
		 
		        // pannello
				 panel.setSize(new Dimension(700,400));
			      panel.setMaximumSize(new Dimension(700,400));
			      panel.setMinimumSize(new Dimension(700,400));
			      panel.setPreferredSize(new Dimension(700,400));
			      panel.setLayout(null);
			     
		 
		        // JLabel
		        JLabel user = new JLabel("Username");
		        JLabel password = new JLabel("Password");
		   
		 
		        // entra button
		        Entra.setBounds(510,265,120, 65);
		        Entra.setBorder(null);
		        Entra.addActionListener(this);
		        Entra.setFont(new Font("Impact",Font.TRUETYPE_FONT,16));
		        Entra.setForeground(new java.awt.Color(64,0,64));
		        //user,password label
		        user.setBounds(30,60, 260,80);
		        password.setBounds(30, 160, 260, 80);
		        user.setForeground(new java.awt.Color(0,0,0));
		       password.setForeground(new java.awt.Color(0,0,0));
		        // campi di inserimento
		       user_tf.setBounds(100, 80, 190, 40);
		        pass_tf.setBounds(100, 180, 190, 40);
		        // aggiungo al panello principale
		    panel.add(user);
		        panel.add(password);
		        panel.add(user_tf);
		        panel.add(pass_tf);
		        panel.add(Entra);
	            frame.add(panel);
		        frame.setResizable(false);
		        frame.pack();
		        frame.setVisible(true);}
		 public static void main(String[]args){
			AccessoStudente f=new AccessoStudente();
			
			  }
							
						
			  
			
		 
		 
			   
				
				//distruggi frame
					public void actionPerformed(ActionEvent ae) {
					
					if(ae.getSource()==Entra && user_tf.getText().length() <= 3 || user_tf.getText().length()>=13){
						
							
								SwingUtilities.invokeLater(new Runnable() {
									public void run() {
									Errore inst = new Errore();
										inst.setLocationRelativeTo(null);
										
								
							        }
								});
								frame.dispose();  }
					else if(ae.getSource()==Entra){
						SwingUtilities.invokeLater(new Runnable() {
							public void run() {
							PagPers inst = new PagPers();
								inst.setLocationRelativeTo(null);
								inst.setVisible(true);
						
					        }
						});
						frame.dispose();  }
					
						
					
				
	      
}

}
